<template>
  <el-breadcrumb separator="/" class="breadcrumb">
    <el-breadcrumb-item to="/home">
      <el-icon><House /></el-icon>
      <span class="crumb-text">首页</span>
    </el-breadcrumb-item>
    <el-breadcrumb-item
      v-for="(routeRecord, index) in matchedRoutes"
      :key="routeRecord.path + index"
    >
      <span class="crumb-text">{{ routeRecord.meta.title || routeRecord.name }}</span>
    </el-breadcrumb-item>
  </el-breadcrumb>
  
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { House } from '@element-plus/icons-vue'

const route = useRoute()

const matchedRoutes = computed(() => {
  // filter root layout and login/register etc. Only show items with a title
  return route.matched
    .filter(r => r.meta && r.meta.title && r.path !== '/')
    .filter(r => r.path !== '/home')
})
</script>

<style scoped>
.breadcrumb {
  display: flex;
  align-items: center;
}

.crumb-text {
  margin-left: 4px;
}

.dark .breadcrumb :deep(.el-breadcrumb__item) {
  color: #e5e7eb;
}
</style>


